package packing;
import geometric3D.*;

public class Block extends BoxShape{
	
	
	SimpleBlock mainBlock;
	SimpleBlock nextBlock;
	BlockRelation relation;
	boolean isSimpleBlock;

	public Block() {
		super();
	}

	public Block(SimpleBlock mainBlock, SimpleBlock nextBlock,
			BlockRelation relation) {
		super();
		this.mainBlock = mainBlock;
		this.nextBlock = nextBlock;
		this.relation = relation;
		this.isSimpleBlock = false;
		int xEnvelope =mainBlock.getWidth();
		int yEnvelope =mainBlock.getLength();
		int zEnvelope =mainBlock.getHeight();
		if(relation==BlockRelation.LEFT){
			xEnvelope = nextBlock.getWidth() + mainBlock.getWidth();
			yEnvelope = Math.max(mainBlock.getLength(), nextBlock.getLength());
			zEnvelope = Math.max(mainBlock.getHeight(), nextBlock.getHeight());
		}else if(relation==BlockRelation.INFRONT){
			xEnvelope = Math.max(nextBlock.getWidth(),mainBlock.getWidth());
			yEnvelope = mainBlock.getLength()+nextBlock.getLength();
			zEnvelope = Math.max(mainBlock.getHeight(), nextBlock.getHeight());
			
		}else if(relation ==BlockRelation.BELOW){
			xEnvelope = Math.max(nextBlock.getWidth(),mainBlock.getWidth());
			yEnvelope = Math.max(mainBlock.getLength(),nextBlock.getLength());
			zEnvelope = mainBlock.getHeight()+nextBlock.getHeight();
			
		}
		this.width  = xEnvelope;
		this.length = yEnvelope;
		this.height = zEnvelope;
	}
	
	public Block(SimpleBlock mainBlock) {
		super();
		this.mainBlock = mainBlock;
		this.isSimpleBlock = true;
		this.width = mainBlock.getWidth();
		this.length = mainBlock.getLength();
		this.height = mainBlock.getHeight();
	}

	public SimpleBlock getMainBlock() {
		return mainBlock;
	}
	public int getWeight(){
		return mainBlock.getBox().getWeight();
	}
	public int getPressure(){
		return mainBlock.getBox().getPressure();
	}
	public void setMainBlock(SimpleBlock mainBlock) {
		this.mainBlock = mainBlock;
	}

	public SimpleBlock getNextBlock() {
		return nextBlock;
	}

	public void setNextBlock(SimpleBlock nextBlock) {
		this.nextBlock = nextBlock;
	}

	public BlockRelation getRelation() {
		return relation;
	}

	public void setRelation(BlockRelation relation) {
		this.relation = relation;
	}

	public boolean isSimpleBlock() {
		return isSimpleBlock;
	}

	public void setSimpleBlock(boolean isSimpleBlock) {
		this.isSimpleBlock = isSimpleBlock;
	}
	
	public long getVolumeAllBox(){
		
		if(nextBlock != null)		
			return mainBlock.getVolume() + nextBlock.getVolume();
		else
			return mainBlock.getVolume();
	}
	
	@Override
	public String toString() {
		return "\nBlock : mainBlock = ( " + mainBlock + " ),\n nextBlock = ( " + nextBlock
				+ " ),\n relation = ( " + relation + " ),\n isSimpleBlock = ( " + isSimpleBlock
				+ " )";
	}
}
